  package server.phone.servlet;

import com.opensymphony.xwork2.ActionSupport;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import server.phone.dao.DeskDAO;
import server.phone.dao.SaleAndPdtDAO;

public class SetSaleAndPdtDeliveredServlet
  extends ActionSupport
{
  private static final long serialVersionUID = -7811568044252827351L;
  private HttpServletRequest request;
  private HttpServletResponse response;
  
  public SetSaleAndPdtDeliveredServlet()
  {
    this.request = ServletActionContext.getRequest();
    this.response = ServletActionContext.getResponse();
  }
  
  private boolean flag = false;
  
  public void doPost()
    throws IOException
  {
    String id = this.request.getParameter("salerecordId");
    String pdtcode = this.request.getParameter("PdtCODE");
    String deskname = this.request.getParameter("DeskName");
    String closeTime = this.request.getParameter("closeTime");
    String createTime = this.request.getParameter("createTime");
    System.out.println("SetSaleAndPdtDeliveredServlet:id=" + id + ";pdtcode=" + pdtcode + ";deskname=" + deskname + ";closeTime=" + closeTime + ";createTime=" + createTime);
    try
    {
      SaleAndPdtDAO srd = new SaleAndPdtDAO();
      DeskDAO dd = new DeskDAO();
      this.flag = srd.updateSaleAndPdt(id, pdtcode, closeTime, createTime, "Delivered");
      if (this.flag) {
        this.flag = dd.updateDeskSub(deskname);
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    JSONObject jObject = new JSONObject();
    try
    {
      if (this.flag) {
        jObject.put("ret", "success");
      }
    }
    catch (Exception e)
    {
      jObject.put("ret", "error");
    }
    PrintWriter out = this.response.getWriter();
    out.println(jObject);
    out.flush();
    out.close();
  }
}
